const cloud = require('wx-server-sdk')
cloud.init({
    env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()

exports.main = async (event, context) => {
    const { tipId } = event

    try {
        // 更新浏览量
        const res = await db.collection('tips').doc(tipId).update({
            data: {
                views: db.command.inc(1)
            }
        })

        return {
            code: 0,
            message: '更新成功'
        }
    } catch (err) {
        console.error('更新浏览量失败:', err)
        return {
            code: -1,
            message: '更新失败'
        }
    }
}